﻿<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
		<title>Clientes</title>
	</head>
	<body>
		
		<center>
			<table border="1px" width="100%">
				<?php include_once "../layout/header.php" ?>
				<tr>
				<?php include_once "../layout/menuCliente.php"?>
				</tr>
			</table>
		</center>
		
		<?php require_once "../includes/config.inc.php";
			
			$sql = "select count(idCliente) as qtd from tbCliente";
			$total = mysql_query($sql);

			if(!$total){
				echo die('Erro: '.mysql_error());
			}
			
			if($t =  mysql_fetch_assoc($total)){
			
			$qtdRegistros = $t['qtd'];
			$registros = 10;
			$paginas = ceil($qtdRegistros / $registros);
			$pagina = empty($_REQUEST['pagina'])?1:$_REQUEST['pagina'];
			$inicio = ($pagina * $registros)-$registros;
			
			$sql = "select * from tbCliente limit $inicio,$registros"; 
			$dados = mysql_query($sql);
	
			echo "<table border='1px' width='100%'> 
			<tr>
				<th> Id </th>
				<th> Nome</th>
				<th> CPF</th>
				<th> RG </th>
				<th> Ações</th>
			</tr> ";
			
			while($row = mysql_fetch_assoc($dados)){
				
				echo "<tr>"; 
				echo"<td>";
				echo $row['idCliente']."</td>";
				echo"<td>";
				echo $row['nomeCliente']."</td>"; 
				echo"<td>";
				echo $row['cpfCliente']."</td>";
				echo "<td>";
				echo $row['rgCliente']."</td>";
				echo "<td>";
				echo "<a href= '/bancophp/cliente/clienteForm.php?usr=".$row['idCliente']."'>Editar </a> ";
				echo "<a href= '/bancophp/removerConfirmCliente.php?usr=".$row['idCliente']."'>Remover</a> </td>";
				echo "</tr>"; 
			}
			include_once "../layout/footer.php";
			
			echo "<center>";
			for($i = 1; $i <= $paginas; $i++){
				echo ($pagina == $i?" <b> ":" ")."<a href ='?pagina=$i'>".$i."</a>".($pagina == $i?" </b> ":" ");
    }
			echo "</center></table><br/>";
}
?>
	</body>
</html>